/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edmo.fastener.business;

import com.edmo.fastener.dao.CustomerOrderDao;
import com.edmo.fastener.domain.CustomerOrder;
import com.edmo.fastener.domain.CustomerOrder;
import java.util.List;
import java.util.Vector;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author obelog
 */
public class SaverToDB implements Runnable {
    private ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"aplication-context.xml"});
    private CustomerOrderDao customerOrderDao = (CustomerOrderDao) context.getBean("customerOrderDao");
    private static List<CustomerOrder> list = new Vector<CustomerOrder>();

    public void run() {
        while(true){
            if(!list.isEmpty()){
                customerOrderDao.save(list.get(0));
                System.out.println("---Save--- " + list.get(0).getId() + " " + System.currentTimeMillis());
                list.remove(0);    
            }
        }
    }

    public static List<CustomerOrder> getList() {
        return list;
    }

    public static void setList(List<CustomerOrder> list) {
        SaverToDB.list = list;
    }
   
    
    
}
